import { defineStore } from 'pinia'
import { reactive, ref, computed } from 'vue'

// pinia组合式API写法 第二个参数接收一个箭头函数,箭头函数必须return对象
const todoStore = defineStore('todo', () => {
  const params = {
    array: [1, 2, 3, 4],
    name: '哈哈',
    test: '测试',
  }
  const data = ref([1, 2, 3, 4, 5, 6])
  const total = computed(() => data.value.reduce((a, b) => a + b))
  let todoData = reactive(params)
  return {
    todoData,
    total,
    changeData() {
      todoData = { ...todoData, test: '修改数据' }
    },
  }
})

export default todoStore
